package com.zhentao.controller;


import com.zhentao.aop.MyLog;
import com.zhentao.domain.SRetakesInfo;
import com.zhentao.domain.dto.RetakesInfoDto;
import com.zhentao.result.Result;
import com.zhentao.service.SRetakesInfoService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;

@RestController
@RequestMapping("/retakes")
@Api(value = "补考信息")
public class RetakesInfoController {

    @Resource
    private SRetakesInfoService retakesInfoService;

    //老师提交补考信息
    @PostMapping("/submitRetakesInfo")
    @MyLog(title = "考试", content = "提交补考信息")
    public Result submitRetakesInfo(@RequestBody SRetakesInfo retakesInfo){
        return retakesInfoService.submitRetakesInfo(retakesInfo);
    }

    //老师查看自己提交的补考信息
    @PostMapping("/getRetakesInfoByTeacher/{tid}")
    public Result getRetakesInfoByTeacher( @PathVariable("tid") Integer tid,@RequestBody RetakesInfoDto retakesInfoDto){
        return retakesInfoService.getRetakesInfoByTeacher(tid,retakesInfoDto);
    }

    //管理员查看补考信息
    @PostMapping("/getRetakesInfo")
    public Result getRetakesInfo(@RequestBody RetakesInfoDto retakesInfoDto){
        return retakesInfoService.getRetakesInfo(retakesInfoDto);
    }

    //管理员审核补考通过
    @GetMapping("/approved/{rid}")
    @MyLog(title = "考试", content = "审核补考通过")
    public Result approved(@PathVariable("rid") Integer rid){
        return retakesInfoService.approved(rid);
    }

    //管理员审核补考不通过
    @GetMapping("/refuse/{rid}/{backCause}")
    @MyLog(title = "考试", content = "审核补考不通过")
    public Result refuse(@PathVariable("rid") Integer rid,@PathVariable("backCause") String backCause){
        return retakesInfoService.refuse(rid,backCause);
    }


    //删除补考信息
    @PostMapping("/deleteRetakesInfo")
    @MyLog(title = "考试", content = "删除补考信息")
    public Result deleteRetakesInfo(@RequestBody Integer[] rid){
        return Result.OK(retakesInfoService.removeBatchByIds(Arrays.asList(rid)));
    }

    //根据补考信息id查找对应的补考信息
    @GetMapping("/getRetakesInfoById/{rid}")
    public Result getRetakesInfoById(@PathVariable("rid") Integer rid){
        return Result.OK(retakesInfoService.getById(rid));
    }

}
